#include <stdio.h>

#include "ringbuffer.h"

int main(void)
{
    uint8_t i = 0;
    uint8_t buffer[16];

    ringbuffer_t *rb = ringbuffer_create(16);
    if(NULL == rb)
    {
        printf("create ringbuffer failed!\n");
        return -1;
    }

    printf("create 16 ringbuffer OK.\n");
    printf("ringbuffer is full : %d\n", ringbuffer_full(rb));
    printf("ringbuffer is empty: %d\n", ringbuffer_empty(rb));
    printf("ringbuffer used    : %d\n", ringbuffer_used(rb));
    printf("ringbuffer remain  : %d\n", ringbuffer_remain(rb));

    for(i = 0; i < 8; i++)
        ringbuffer_put(rb, &i, 1);

    printf("\ninsert 8 bytes data.\n");
    printf("ringbuffer is full : %d\n", ringbuffer_full(rb));
    printf("ringbuffer is empty: %d\n", ringbuffer_empty(rb));
    printf("ringbuffer used   : %d\n", ringbuffer_used(rb));
    printf("ringbuffer remain : %d\n", ringbuffer_remain(rb));

    for(; i < 16; i++)
        ringbuffer_put(rb, &i, 1);

    printf("\ninsert 8 bytes data.\n");
    printf("ringbuffer is full : %d\n", ringbuffer_full(rb));
    printf("ringbuffer is empty: %d\n", ringbuffer_empty(rb));
    printf("ringbuffer used   : %d\n", ringbuffer_used(rb));
    printf("ringbuffer remain : %d\n", ringbuffer_remain(rb));

    ringbuffer_get(rb, buffer, 10);
    printf("\nget 10 bytes:");
    for(i = 0; i < 10; i++)
        printf(" %d", buffer[i]);
    printf("\nringbuffer is full : %d\n", ringbuffer_full(rb));
    printf("ringbuffer is empty: %d\n", ringbuffer_empty(rb));
    printf("ringbuffer used   : %d\n", ringbuffer_used(rb));
    printf("ringbuffer remain : %d\n", ringbuffer_remain(rb));

    for(i = 0; i < 7; i++)
        ringbuffer_put(rb, &i, 1);

    printf("\ninsert 7 bytes data.\n");
    printf("ringbuffer is full : %d\n", ringbuffer_full(rb));
    printf("ringbuffer is empty: %d\n", ringbuffer_empty(rb));
    printf("ringbuffer used   : %d\n", ringbuffer_used(rb));
    printf("ringbuffer remain : %d\n", ringbuffer_remain(rb));

    ringbuffer_get(rb, buffer, 13);
    printf("\nget 13 bytes:");
    for(i = 0; i < 13; i++)
        printf(" %d", buffer[i]);
    printf("\n");

    for(i = 0; i < 32; i++)
        ringbuffer_put_cover(rb, &i, 1);

    printf("\ninsert 32 bytes data.\n");
    printf("ringbuffer is full : %d\n", ringbuffer_full(rb));
    printf("ringbuffer is empty: %d\n", ringbuffer_empty(rb));
    printf("ringbuffer used   : %d\n", ringbuffer_used(rb));
    printf("ringbuffer remain : %d\n", ringbuffer_remain(rb));

    ringbuffer_get(rb, buffer, 16);
    printf("\nget 16 bytes:");
    for(i = 0; i < 16; i++)
        printf(" %d", buffer[i]);
    printf("\n");

    ringbuffer_destroy(rb);

    return 0;
}
